﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Role_Create.aspx.cs" Inherits="SYS_POPEDOM_Role_Create" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link href="../css/PageStyle.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .no-Icon
        {
            display: none;
        }
    </style>

    <script type="text/javascript" src="../JavaScript/Common.js"></script>

    <script type="text/javascript">
        function nodeLoad(node) {
            Ext.net.DirectMethods.NodeLoad(node.id, {
                success: function(result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },
                failure: function(errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }
        function clickRoot(node) {
            extTp_Fuc.fireEvent("click", node);
        }
        function loadPopPage(url) {
            var hostName, win;
            hostName = window.location.protocol + "//" + window.location.host;
            win = popWindow.add(new Ext.Panel({
                id: 'pnlContainer',
                height: 348,
                border: false,
                autoLoad: {
                    showMask: true,
                    scripts: true,
                    mode: "iframe",
                    url: hostName + url
                },
                closable: true
            }));
        }
        function PopWin() {
            var hostName = window.location.protocol + "//" + window.location.host;
            var linkUrl = hostName + "/CommonPages/SelectRoleMenu.aspx?sub_system=" + extHid_NodeId.Value;
            popWindow.loadContent(linkUrl, true);
            popWindow.show();
        };
        function TempSaveNodeId(node) {
            Ext.net.DirectMethods.GetNodeIdTempSave(node.id);
        }
    
    </script>

    <script type="text/javascript">
        function nodeLoadWin(node) {
            Ext.net.DirectMethods.NodeLoadWin(node.id, node.getUI().isChecked(), {
                success: function(result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },
                failure: function(errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }
        function refreshTree(tree) {
            tree.root.ui.remove();
            tree.root.render();
            Ext.net.DirectMethods.RefreshMenu({
                success: function(result) {
                    var nodes = eval(result);
                    tree.initChildren(nodes);
                    tree.root.render();
                }
            });
        }
        function getCheckedNode() {
            var result = "";
            var checkeds = Ext.getCmp('roleTree').getChecked();
            for (var i = 0; i < checkeds.length; i++) {
                result = result + checkeds[i].id + ";";
            }
            result = result.substring(0, result.length - 1)
            return result;
        }

        function SaveWin() {
            extHid_RoleMenu.value = getCheckedNode();
            popWindow.hide();
            extBtn_AddMenu.fireEvent("click", "");
        }

        function ClostWin() {
            popWindow.hide();
        }


        function ClickNodeResh(id, text) {
            GridPanel1.body.mask('Loading...', 'x-mask-loading');
            document.getElementById('cbAll').checked = false;
            GridPanel1.save();
            Ext.net.DirectMethods.nodeClick(id, text, {
                success: function(result) {
                    GridPanel1.store.load({ callback: function() { GridPanel1.body.unmask(); } });
                }
            });
        }
        function SeclectRead() {
            GridPanel1.body.mask('Loading...', 'x-mask-loading');
            var id = extTp_Fuc.getSelectionModel().getSelectedNode().id;
            var txt = extTp_Fuc.getSelectionModel().getSelectedNode().text;
            GridPanel1.save();
            Ext.net.DirectMethods.SeclectRead(id, txt, document.getElementById('cbAll').checked, GetAllRecord(), {
                success: function(result) {
                    GridPanel1.store.load({ callback: function() { GridPanel1.body.unmask(); } });
                }
            });
        }
        function GetAllRecord() {
            var recordData = [];
            var grid = Ext.getCmp('GridPanel1');
            Ext.each(grid.getStore().getRange(), function(record) {
                recordData.push(record.data);
            });
            var jsonData = Ext.encode(recordData);
            return jsonData;
        }
    </script>

</head>
<body>

    <script type="text/javascript">
        Ext.override(Ext.grid.CheckboxSelectionModel, {
            onMouseDown: function(e, t) {
                if (e.button === 0 && (!this.checkOnly || (this.checkOnly && t.className == "x-grid3-row-checker")) && t.className != "x-grid3-row-expander" && !Ext.fly(t).hasClass("x-grid3-td-expander")) {
                    e.stopEvent();

                    var row = e.getTarget(".x-grid3-row");

                    if (row) {
                        var index = row.rowIndex;

                        if (this.isSelected(index)) {
                            if (!this.grid.enableDragDrop) {
                                if (!this.allowDeselect) {
                                    return;
                                }

                                this.deselectRow(index);
                            } else {
                                this.deselectingFlag = true;
                            }
                        } else {
                            if (this.grid.enableDragDrop) {
                                this.deselectingFlag = false;
                            }

                            this.selectRow(index, true);
                        }
                    }
                }
            }
        });
    </script>

    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" AjaxViewStateMode="Enabled" />
    <ext:Store ID="Store1" runat="server" AutoLoad="true" OnBeforeRecordUpdated="Store1_BeforeRecordUpdated">
        <Reader>
            <ext:JsonReader IDProperty="MENU_NO">
                <Fields>
                    <ext:RecordField Name="MENU_NO" />
                    <ext:RecordField Name="MENU_NAME" />
                    <ext:RecordField Name="READONLY" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="Fit">
        <Content>
            <ext:Panel runat="server" Layout="FitLayout" Border="false">
                <TopBar>
                    <ext:Toolbar ID="Toolbar3" runat="server">
                        <Items>
                            <ext:Button ID="extBtn_Save" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{GridPanel1}.save();" />
                                </Listeners>
                                <DirectEvents>
                                    <Click OnEvent="extBtn_SaveClick">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                            <ext:Button ID="extBtn_Cancel" runat="server" Text="关闭" Icon="Cancel">
                                <Listeners>
                                    <Click Fn="closeCurrTab" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Content>
                    <ext:RowLayout ID="RowLayout1" runat="server">
                        <Rows>
                            <ext:LayoutRow>
                                <ext:Panel ID="pnlTableLayout" runat="server" Border="false" BodyStyle="padding:2px;"
                                    Title="角色信息" Height="149" EnableViewState="true">
                                    <Content>
                                        <table width="100%" cellpadding="3px" cellspacing="3px">
                                            <tr height="25px">
                                                <td width="15%" align="right" style="text-align: right">
                                                    <label id="Label18" class="css_p9" runat="server">
                                                        角色代码：</label>
                                                </td>
                                                <td width="35%">
                                                    <ext:TextField ID="extTf_RoleID" runat="server" AllowBlank="true" StyleSpec="width:80%"
                                                        BlankText="角色代码不能为空!" LabelStyle="text-align:right;">
                                                    </ext:TextField>
                                                </td>
                                                <td width="15%" align="right" style="text-align: right">
                                                    <label id="Label1" class="css_p9" runat="server">
                                                        角色名称：</label>
                                                </td>
                                                <td width="35%">
                                                    <ext:TextField ID="extTf_RoleName" runat="server" AllowBlank="false" StyleSpec="width:80%"
                                                        BlankText="角色名称不能为空!" LabelStyle="text-align:right;">
                                                    </ext:TextField>
                                                </td>
                                            </tr>
                                            <tr height="25px">
                                                <td width="15%" align="right" style="text-align: right">
                                                    <label id="Label2" class="css_p9" runat="server">
                                                        创建者：</label>
                                                </td>
                                                <td width="35%" align="left">
                                                    <ext:TextField ID="extTf_Creator" runat="server" ReadOnly="true" LabelStyle="text-align:right;"
                                                        StyleSpec="width:80%">
                                                    </ext:TextField>
                                                </td>
                                                <td width="15%" align="right" style="text-align: right">
                                                    <label id="Label3" class="css_p9" runat="server" title="创建部门：">
                                                        创建部门：</label>
                                                </td>
                                                <td width="35%" align="left">
                                                    <ext:TextField ID="extTf_CreatorDept" runat="server" ReadOnly="true" LabelStyle="text-align:right;"
                                                        StyleSpec="width:80%">
                                                    </ext:TextField>
                                                </td>
                                            </tr>
                                            <tr height="55px">
                                                <td width="15%" align="right" style="text-align: right">
                                                    <label id="Label4" class="css_p9" runat="server">
                                                        备注：</label>
                                                </td>
                                                <td colspan="3" width="60%">
                                                    <ext:TextArea ID="extTa_Notes" runat="server" LabelStyle="text-align:right;" StyleSpec="width:92%"
                                                        Height="50">
                                                    </ext:TextArea>
                                                </td>
                                            </tr>
                                        </table>
                                    </Content>
                                </ext:Panel>
                            </ext:LayoutRow>
                            <ext:LayoutRow RowHeight="1">
                                <ext:Panel ID="Panel1" runat="server" Title="" Cls="tool-form" BodyStyle="border-width:1px 0px 0px 0px;padding-top:0;"
                                    Layout="Fit">
                                    <Content>
                                        <ext:ColumnLayout ID="ColumnLayout1" runat="server" Split="false" Border="false"
                                            FitHeight="true">
                                            <Columns>
                                                <ext:LayoutColumn>
                                                    <ext:Panel ID="Panel3" runat="server" Border="false" Header="false" AutoScroll="false"
                                                        Layout="Fit" Width="251">
                                                        <Items>
                                                            <ext:TreePanel ID="extTp_Fuc" runat="server" BodyStyle="border-width:0 1px 0 0;"
                                                                CollapseFirst="false" AutoScroll="true" ContainerScroll="true">
                                                                <Root>
                                                                    <ext:AsyncTreeNode NodeID="0" Text="全部子系统" Expanded="true" />
                                                                </Root>
                                                                <Listeners>
                                                                    <BeforeLoad Fn="nodeLoad" />
                                                                    <Click Handler="ClickNodeResh(node.id,node.text);" />
                                                                    <ExpandNode Fn="clickRoot" />
                                                                    <CollapseNode Fn="clickRoot" />
                                                                </Listeners>
                                                            </ext:TreePanel>
                                                        </Items>
                                                    </ext:Panel>
                                                </ext:LayoutColumn>
                                                <ext:LayoutColumn ColumnWidth="1">
                                                    <ext:Panel ID="Panel4" runat="server" Border="false" Layout="Fit">
                                                        <Items>
                                                            <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" Border="false" AutoWidth="true"
                                                                StripeRows="true" Collapsible="false" AutoShow="true" AutoExpandColumn="MENU_NAME">
                                                                <ColumnModel ID="ColumnModel1" runat="server">
                                                                    <Columns>
                                                                        <ext:RowNumbererColumn />
                                                                        <ext:Column ColumnID="MENU_NO" Hidden="true" DataIndex="MENU_NO">
                                                                        </ext:Column>
                                                                        <ext:Column Header="功能名称" Width="75" Sortable="true" DataIndex="MENU_NAME">
                                                                        </ext:Column>
                                                                        <ext:CheckColumn Header="<center>只读<input id='cbAll' type='checkbox' onclick='SeclectRead();' /></center>"
                                                                            DataIndex="READONLY" Sortable="false" Editable="true" Hideable="true">
                                                                        </ext:CheckColumn>
                                                                    </Columns>
                                                                </ColumnModel>
                                                                <SelectionModel>
                                                                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" ColumnPosition="1">
                                                                        <CustomConfig>
                                                                            <ext:ConfigItem Name="checkOnly" Value="true" Mode="Raw" />
                                                                        </CustomConfig>
                                                                    </ext:CheckboxSelectionModel>
                                                                </SelectionModel>
                                                                <LoadMask ShowMask="true" />
                                                            </ext:GridPanel>
                                                        </Items>
                                                    </ext:Panel>
                                                </ext:LayoutColumn>
                                            </Columns>
                                        </ext:ColumnLayout>
                                    </Content>
                                    <TopBar>
                                        <ext:Toolbar ID="Toolbar1" runat="server">
                                            <Items>
                                                <ext:Label ID="t" runat="server" Text="功能导航">
                                                </ext:Label>
                                                <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                                                <ext:Button ID="extBtn_Add" runat="server" Text="增加" Icon="Add">
                                                    <Listeners>
                                                        <Click Handler="#{GridPanel1}.save();refreshTree(#{roleTree});#{popWindow}.show();" />
                                                    </Listeners>
                                                </ext:Button>
                                                <ext:Button ID="extBtn_Delete" runat="server" Text="删除" Icon="Delete">
                                                    <DirectEvents>
                                                        <Click OnEvent="DelFunc">
                                                        </Click>
                                                    </DirectEvents>
                                                </ext:Button>
                                            </Items>
                                        </ext:Toolbar>
                                    </TopBar>
                                </ext:Panel>
                            </ext:LayoutRow>
                        </Rows>
                    </ext:RowLayout>
                </Content>
            </ext:Panel>
        </Content>
    </ext:Viewport>
    <ext:Hidden ID="extHid_NodeId" runat="server" Text="">
    </ext:Hidden>
    <ext:Hidden ID="extHid_RoleMenu" runat="server" Text="">
    </ext:Hidden>
    <ext:Button ID="extBtn_AddMenu" runat="server" Hidden="true">
        <Listeners>
            <Click Handler="Ext.net.DirectMethods.refrashDataEvent(#{extHid_RoleMenu}.value);" />
        </Listeners>
    </ext:Button>
    <input id="htmlHid_RoleMenu" runat="server" value="" type="hidden" />
    <ext:Window ID="popWindow" runat="server" Icon="Group" Title="" Width="400" Height="380"
        AutoShow="false" Modal="true" Hidden="true" Closable="true" Resizable="true"
        Draggable="false">
        <Content>
            <ext:Panel ID="Panel2" runat="server" Border="false" Height="320">
                <Items>
                    <ext:FitLayout ID="FitLayout1" runat="server">
                        <Items>
                            <ext:TreePanel ID="roleTree" runat="server" Lines="false" Border="false" CollapseFirst="false"
                                AutoScroll="true" ContainerScroll="true" RootVisible="false">
                                <Root>
                                    <ext:AsyncTreeNode NodeID="0" Text="Root1" />
                                </Root>
                                <Listeners>
                                    <BeforeLoad Fn="nodeLoadWin" />
                                    <CheckChange Fn="checkNode" />
                                </Listeners>
                                <LoadMask ShowMask="true" />
                            </ext:TreePanel>
                        </Items>
                    </ext:FitLayout>
                </Items>
            </ext:Panel>
        </Content>
        <TopBar>
            <ext:Toolbar runat="server">
                <Items>
                    <ext:Button ID="btnSave" runat="server" Text="确定" Icon="Disk">
                        <Listeners>
                            <Click Fn="SaveWin" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="btnCancel" runat="server" Text="关闭" Icon="Cancel">
                        <Listeners>
                            <Click Fn="ClostWin" />
                        </Listeners>
                    </ext:Button>
                     <ext:ToolbarFill ID="ToolbarFill2" runat="server">
                    </ext:ToolbarFill>
                </Items>
            </ext:Toolbar>
        </TopBar>
    </ext:Window>
    </form>
</body>
</html>
